﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfUMLTry1;

namespace WpfUMLTry1.ViewModel
{
    class CreateChar_VM : VM_Base
    {
        private String _name;
        private Model.gameModel _gModel;
        private Int32 slotNumber;

        public String CharacterName { 
            get { return _name; } 
            set { _name = value; OnPropertyChanged("CharacterName"); } 
        }

        public DelegateCommand CreateCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }

        #region radio button handling
        private Boolean _radioB1;
        private Boolean _radioB2;
        private Boolean _radioB3;

        public Boolean radioB1
        {
            get { return _radioB1; }
            set
            {
                _radioB1 = value;
                //_radioB2 = false;
                //_radioB3 = false;
                if (_radioB1 == true)
                {
                    STR = 8;
                    AGI = 5;
                    VIT = 8;
                    WIS = 2;
                    LUK = 2;
                }
                refreshRadioButton();
            }
        }
        public Boolean radioB2
        {
            get { return _radioB2; }
            set
            {
                _radioB2 = value;
                if (_radioB2 == true)
                {
                    STR = 3;
                    AGI = 4;
                    VIT = 5;
                    WIS = 9;
                    LUK = 4;
                }
                refreshRadioButton();
            }
        }
        public Boolean radioB3
        {
            get { return _radioB3; }
            set
            {
                _radioB3 = value;
                //_radioB2 = false;
                //_radioB1 = false;
                if (_radioB3 == true)
                {
                    STR = 6;
                    AGI = 7;
                    VIT = 4;
                    WIS = 1;
                    LUK = 7;
                }
                refreshRadioButton();
            }
        }
        private void refreshRadioButton()
        {
            OnPropertyChanged("radioB1");
            OnPropertyChanged("radioB2");
            OnPropertyChanged("radioB3");
        }
        #endregion

        #region Stats
        List<Int32> bStats;

        public Int32 STR
        {
            get { return bStats[0]; }
            set
            {
                bStats[0] = value; OnPropertyChanged("STR");
            }
        }
        public Int32 AGI
        {
            get { return bStats[1]; }
            set
            {
                bStats[1] = value; OnPropertyChanged("AGI");
            }
        }
        public Int32 VIT
        {
            get { return bStats[2]; }
            set
            {
                bStats[2] = value; OnPropertyChanged("VIT");
            }
        }
        public Int32 WIS
        {
            get { return bStats[3]; }
            set
            {
                bStats[3] = value; OnPropertyChanged("WIS");
            }
        }
        public Int32 LUK
        {
            get { return bStats[4]; }
            set
            {
                bStats[4] = value; OnPropertyChanged("LUK");
            }
        }
        #endregion

        public CreateChar_VM(Int32 slotNum)
        {
            slotNumber = slotNum;
            CharacterName = "Aktrok";
            bStats = new List<Int32>(5);
            for (int i = 0; i < 5; ++i)
                bStats.Add(0);
            radioB1 = true;
            CreateCommand = new DelegateCommand(param => CreateAndStart());
            CancelCommand = new DelegateCommand(param => View.Switcher.Switch(new View.CharSelect(), new WpfUMLTry1.ViewModel.CharSelect_VM()));
        }

        private void CreateAndStart()
        {
            Model.PlayerCharacter ply;
            if(radioB1)
                ply = new Model.Classes.Warrior(CharacterName);
            else if(radioB2)
                ply = new Model.Classes.Mage(CharacterName);
            else
                ply = new Model.Classes.Rogue(CharacterName);
            ply.SetAllStat(bStats);
            Model.gameModel _gModel = new Model.gameModel(slotNumber);
            _gModel.addCharacterToTheGame(ply);
            _gModel.numberOfSaveSlot = slotNumber;
            View.Switcher.Switch(new View.InTheTown(_gModel));
            _gModel.followTheSigns();
            
        }

        public void ResetData()
        {
            CharacterName = "Aktrok";
            radioB1 = true;
        }
    }
}
